package com.mapper;

import com.mybatisflex.core.BaseMapper;
import com.entity.BUser;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 管理员表 映射层。
 *
 * @author admin
 * @since 2024-05-21
 */
@Mapper
public interface BUserMapper extends BaseMapper<BUser> {
    // 根据ID查询后台用户
    @Select("SELECT * FROM b_user WHERE id = #{id}")
    BUser findById(Integer id);

    // 插入后台用户
    @Insert("INSERT INTO b_user(username, pwd, phone) VALUES (#{username}, #{pwd}, #{phone})")
    int insertAdmin(BUser bUser);

    // 更新后台用户
    @Update("UPDATE b_user SET username = #{username}, pwd = #{pwd}, phone = #{phone} WHERE id = #{id}")
    int updateAdmin(BUser bUser);

    // 删除后台用户（根据ID）
    @Delete("DELETE FROM b_user WHERE id = #{id}")
    int deleteAdminById(Integer id);

    // 查询所有后台用户
    @Select("SELECT * FROM b_user")
    List<BUser> findAllAdmins();

    // 根据用户名和密码查询后台用户（用于登录）
    @Select("SELECT * FROM b_user WHERE username = #{username} AND pwd = #{pwd}")
    public BUser userLogin(BUser bUser);
}
